<template>
	<audio v-show="imgUrl" controls :src="imgUrl"></audio>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { DowloadPreviewImage } from '@/utils/util'

export default defineComponent({
	props: {
		src: {
			type: String,
		},
	},
	setup(props, { emit }) {
		const imgUrl = ref('')
		const fileName = ref(props.src?.slice(-12))
		const getPreviewImage = async () => {
			if (props.src?.includes('ningxiang')) {
				const previewUrl = (await DowloadPreviewImage(props.src)) as string
				imgUrl.value = previewUrl
			} else {
				imgUrl.value = props.src
			}
		}
		watch(
			() => props.src,
			() => {
				getPreviewImage()
			},
			{
				immediate: true,
			}
		)

		return {
			imgUrl,
			fileName,
		}
	},
})
</script>

<style scoped lang="scss">
.preview-img-box {
	width: 128px;
	height: 128px;
	.el-image {
		img {
			width: 100%;
			height: 100%;
		}
	}
}
</style>
